package com.funtonow.jqdk.upload;

import com.funtonow.jqdk.base.SqjAppliaction;
import com.tencent.qcloud.core.auth.BasicLifecycleCredentialProvider;
import com.tencent.qcloud.core.auth.QCloudLifecycleCredentials;
import com.tencent.qcloud.core.auth.SessionQCloudCredentials;
import com.tencent.qcloud.core.common.QCloudClientException;

/**
 * @author Jiajien
 * @date 2019/5/6
 */
public class MyCredentialProvider extends BasicLifecycleCredentialProvider {

    @Override
    protected QCloudLifecycleCredentials fetchNewCredentials() throws QCloudClientException {

        // 首先从您的临时密钥服务器获取包含了签名信息的响应
        // 然后解析响应，获取密钥信息
        String tmpSecretId = SqjAppliaction.tencentSecretBean.getCredentials().getTmpSecretId();
        String tmpSecretKey = SqjAppliaction.tencentSecretBean.getCredentials().getTmpSecretKey(); //临时密钥 secretKey
        String sessionToken = SqjAppliaction.tencentSecretBean.getCredentials().getSessionToken(); //临时密钥 Token
        long expiredTime = SqjAppliaction.tencentSecretBean.getExpiredTime();//临时密钥有效截止时间

        // 返回服务器时间作为签名的起始时间
        long beginTime = SqjAppliaction.tencentSecretBean.getStartTime(); //临时密钥有效起始时间

        // todo something you want

        // 最后返回临时密钥信息对象
        return new SessionQCloudCredentials(tmpSecretId, tmpSecretKey, sessionToken, beginTime, expiredTime);
    }
}
